import { HideAndSeekModule } from "./module";
import { HideAndSeekRole } from "./player";

export class HideAndSeekEndState extends HideAndSeekModule.State<{
    winner: "hider" | "seeker" | null;
}> {
    override onEnter(): void {
        if (this.config?.winner == "hider") {
            this.context.players.title("§a躲藏者获胜");
            const names = this.context.players
                .filter((p) => p.alive && p.role == HideAndSeekRole.Hider)
                .map((p) => p.name);
            this.context.players.sendMessage(
                `游戏结束，躲藏者获胜，幸存者：` + names.join(",")
            );
        } else if (this.config?.winner == "seeker") {
            this.context.players.title("§4追捕者获胜");
            const names = this.context.players
                .filter((p) => p.alive && p.role == HideAndSeekRole.Seeker)
                .map((p) => p.name);
            this.context.players.sendMessage("游戏结束，追捕者获胜");
        }
        //延迟一会结束
        this.runner.runDelay(() => {
            this.engine.stopGame();
        }, 40);
    }
}
